package com.plm.maque.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * Configuration和EnableSwagger2这两个注解标签用于自动加载swagger的配置文件
 * @author Limi
 * @create 2020-06-29 13:11
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig  {

    /**
     * 方法名api自定义
     * @return
     */
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.plm.maque.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * swagger界面标题，联系人（含姓名，链接，邮箱），描述，版本，最后build这个文件
     * @return
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder().title("api接口文档")
                .version("1.0.0")
                .build();
    }
}
